package kr.hkit.androidcomplete02.ch01;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ManyItem extends Activity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_view_test);
		
		((ListView)findViewById(R.id.ch12_list)).setAdapter(new ManyAdapter(this));
	}
	class ManyAdapter extends BaseAdapter{
		Context maincon;
		LayoutInflater Inflater;
		Toast mToast;

		public ManyAdapter(Context context) {
			maincon = context;
			Inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}

		@Override
		public int getCount() {
			return 1000;
		}

		@Override
		public Object getItem(int position) {
			return "" + position;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			String log = "position = " + position + ",";
			if (convertView == null){
				convertView = Inflater.inflate(android.R.layout.simple_list_item_1, parent,false);
				log += "convertView is null";
			}else{
				log += "convertView is not null";
			}
			Log.d("ManyItem", log);
			
			if (mToast == null){
				mToast = Toast.makeText(maincon, log, 0);
			}else{
				mToast.setText(log);
				
			}
			mToast.show();
			
			TextView txt = (TextView) convertView.findViewById(android.R.id.text1);
			txt.setText("ManyItem ListView : " + position);
			return convertView;
		}
		
	}
}
